package DesignPattern.NullObjectPattern;


/**
 * 在空对象模式（Null Object Pattern）中，一个空对象取代 NULL 对象实例的检查。
 * Java8中使用Optional
 * */
public class Client {
    public static void main(String[] args) {
        Operation add = OperationFactory.createOperation("add");
        Operation subtract = OperationFactory.createOperation("subtract");
        Operation multiply = OperationFactory.createOperation("multiply");
        Operation divide = OperationFactory.createOperation("divide");
        Operation nullOperation = OperationFactory.createOperation("unknown");

        int resultAdd = add.apply(5, 3);
        int resultSubtract = subtract.apply(5, 3);
        int resultMultiply = multiply.apply(5, 3);
        int resultDivide = divide.apply(6, 2);
        int resultNull = nullOperation.apply(1, 1);

        System.out.println("Result Add: " + resultAdd);
        System.out.println("Result Subtract: " + resultSubtract);
        System.out.println("Result Multiply: " + resultMultiply);
        System.out.println("Result Divide: " + resultDivide);
        System.out.println("Result Null: " + resultNull);
    }
}
